package com.zs.java.base;


/**
 * @author madison
 * @description
 * @date 2021/5/29 12:00
 */
public class InnerClass {
    private int age = 0;

    public static void main(String[] args) {
        InnerClass innerClass = new InnerClass();
        innerClass.getUserInfo();

        Teacher teacher = new Teacher();
        teacher.userInfo();
    }

    private void getUserInfo() {
        User user = new User();
        user.userInfo();

        class Student {
            private String name;

            public void stuInfo() {
                System.out.println("局部内部类:student info");
            }
        }

        Student student = new Student();
        student.stuInfo();

        User user1 = new User() {
            @Override
            public void userInfo() {
                System.out.println("匿名内部类:user info");
            }
        };
        user1.userInfo();
//        user1.age();

        User user2 = new Son();
        user2.userInfo();
        User.age();
        user2.age();

        ((Person) () -> System.out.println("匿名内部类:person info")).userInfo();

        var person = new Person() {

            @Override
            public void userInfo() {
                System.out.println("person info");
            }
        };
        person.getAge();
        Person.showStatic(20);
        System.out.println(Person.age);
    }

    private class User {
        public void userInfo() {
            System.out.println("成员内部类:user info" + age);
        }

        public static int age() {
            System.out.println("user age");
            return 19;
        }
    }

    private class Son extends User {
        @Override
        public void userInfo() {
            System.out.println("son info");
        }
    }


    private static class Teacher {
        public void userInfo() {
            System.out.println("静态内部类:teacher info");
        }
    }

    interface Person {
        int age = 18;

        void userInfo();

        default int getAge() {
            System.out.println("age=" + age);
            return age;
        }

        /**
         * 静态方法
         */
        static int showStatic(int age) {
            System.out.println("Person age=" + age);
            return age;
        }
    }
}
